const gulp = require("gulp");
const gulpLess = require("gulp-less");
const gulpSass = require("gulp-sass")(require("node-sass"));
const fs = require("fs");
const { Transform } = require("stream");
const gulpCleanCss = require("gulp-clean-css");
const gulpRename = require("gulp-rename");

//4版本写法
const test_less = (done) => {
  gulp.src("src/sass/*.sass").pipe(gulpSass()).pipe(gulp.dest("dist/css/"));
  done();
};

//压缩css代码-gulp-clean-css
const test_minicss = (done) => {
  gulp
    .src("src/css/*.css")
    .pipe(gulpCleanCss())
    .pipe(gulpRename({ extname: ".min.css" }))
    .pipe(gulp.dest("dist/css/"));
  done();
};
exports.test_minicss = test_minicss;

//原理分析
// const stream = (done) => {
//   const readStream = fs.createReadStream("package.json");
//   const writeStream = fs.createWriteStream("temp.txt");
//   readStream.pipe(writeStream);
//   readStream.on("end", () => {
//     done();
//   });
// };

// const stream = (done) => {
//   const readStream = fs.createReadStream("package.json");
//   const writeStream = fs.createWriteStream("temp.txt");
//   readStream.pipe(writeStream);
//   return readStream;
// };

// const streamT = (done) => {
//   const readStream = fs.createReadStream("package.json");
//   const writeStream = fs.createWriteStream("temp.txt");
//   const transform = new Transform({
//     transform: (chunk, encoding, callback) => {
//       const input = chunk.toString();
//       const output = input.replace(/\s+/g, "").replace(/\/\*.+?\*\//g, "");
//       callback(null, output);
//     },
//   });

//   readStream.pipe(transform).pipe(writeStream);
//   return readStream;
// };

// module.exports = {
//   test_less,
//   stream,
//   streamT,
// };
